package com.lindroy.androidplayer.ui.adapter

import android.text.Html
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lindroy.androidplayer.R
import com.lindroy.androidplayer.logic.model.ArticleResp
import com.lindroy.lib_utils.extensions.getResString

/**
 * @author Lin
 * @date 2021/4/25
 * @function
 */
class QuestionAdapter : BaseQuickAdapter<ArticleResp, BaseViewHolder>(R.layout.knowledge_question_item) {
    private var collectListener: ((collect: Boolean, id: Int) -> Unit)? = null

    override fun convert(holder: BaseViewHolder, item: ArticleResp) {
        holder.setText(R.id.tvTitle, item.title)
            .setText(R.id.tvDate, item.niceDate)
            .setText(R.id.tvAuthor,item.author)
            .setText(
                R.id.tvChapterName,
                getResString(R.string.home_item_tag, item.superChapterName, item.chapterName)
            )
            .setText(R.id.tvDesc,Html.fromHtml(item.desc))
            .setGone(R.id.tvFresh,item.fresh.not())
        holder.getView<ImageView>(R.id.ivCollect).also {
            it.setImageResource(item.collectIconId)
            it.setOnClickListener {
                collectListener?.invoke(item.collect, item.id)
            }
        }
    }

    /**
     * 收藏按钮点击监听
     */
    fun setOnCollectClickListener(call: (collect: Boolean, id: Int) -> Unit) {
        collectListener = call
    }
}